package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class UserServiceImpl implements UserService {
    
    @Autowired
    private UserMapper mapper;
    
    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public int add(User user) {
        return mapper.insert(user);
    }
    
    /**
     * 根据手机号码查询用户
     *
     * @param phone
     * @return
     */
    @Override
    public User findUser(String phone) {
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.eq(User::getPhone , phone);
        return mapper.selectOne(qw);
    }
}
